package cn.antsing.stream;

import cn.antsing.entity.ProductInfo;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

/**
 * @author sunyuanqing
 * @company www.fishonline.com
 * @date 2018/5/2 0002
 */
public class Main {
    public static void main(String[] args) {
        List<ProductInfo> infoList = new ArrayList<>();
        Random random = new Random();
        for(int i=0;i<20;i++){
            ProductInfo productInfo = new ProductInfo();
            productInfo.setProductId(String.valueOf(i+1));
            productInfo.setProductName("name"+i);
            productInfo.setProductStock(random.nextInt(500));
            System.out.println(productInfo.getProductStock()+"--"+productInfo.getProductName());
            infoList.add(productInfo);
        }
        //List<String> nameList = infoList.stream().map(product->product.getProductName()+product.getProductStock()).collect(Collectors.toList());
        List<String> nameList = infoList.stream().map(ProductInfo::getProductName).collect(Collectors.toList());
        for(String str:nameList)
            System.out.println(str);
    }
}
